//
//$Id: islsp_ga.h 663 2011-02-26 10:41:57Z andrew.tsyganov $
#pragma once

#include "projects/islsp/islsp.h"
#include "solvers/ga/ga_common.h"

//__________________________________________________________________________________
//__________________________________________________________________________________
template<>
struct solution<Islsp_Solution, ga_tag>:
    public Islsp_Solution
{
public:
    mutable double wheel_sector_;

    // simple one-point crossover
    template<class E>
    void cross(E* env, random_generator& rnd, solution<Islsp_Solution, ga_tag>& genome)
    {
        size_t j = 1 + rnd.next_SizeT(env->problem_.p_ - 1);

        for (size_t i = j; i < size_t(env->problem_.p_); ++i) 
            std::swap(t_[i], genome.t_[i]);

        changed_ = genome.changed_ = true;
    }
    
    template<class E>
    void mutate(E* env, random_generator& rnd, double mutationProbability)
    {
        for (size_t i = 0; i < size_t(env->problem_.p_); ++i)
        {
            if (rnd.next_Double() < mutationProbability)
            {
                t_[i] = env->problem_.Delta_(i, 0) + rnd.next_Double() * (env->problem_.Delta_(i, 1) - env->problem_.Delta_(i, 0));
                /*
                double t = t_[i] + 10*rnd.next_Normal(0, 1);
                if (t < env->problem_.Delta_(i, 0)) 
                    t_[i] = env->problem_.Delta_(i, 0);
                else
                    if (t > env->problem_.Delta_(i, 1))
                        t_[i] = env->problem_.Delta_(i, 1);
                    else
                        t_[i] = t;
                */
                //t_[i] += 10*rnd.next_Normal(0, 1);
            }
        }

        changed_ = true;
    }

    TCostType get_Fitness() const { return get_Cost(); }
};
//__________________________________________________________________________________

//EOF!
